<?php

namespace app\index\model;

use think\Cache;
use think\Db;
use think\Model;

class QjConfigModel extends Model {

    public function addConfig($data)
    {
        $res['success'] = false;
        $res['desc'] = '添加失败';
        $res['errorcode'] = '200022';
        if (empty($data))  return $res;
        $ret = Db::table('qj_config')->insert($data);
        if ($ret) {
            $id = Db::table('qj_config')->getLastInsID();
            $res['success'] = true;
            $res['desc'] = '添加成功';
            $res['data']['id'] = $id;
            $res['errorcode'] = '';
        }
        return $res;
    }

    public function upConfigInfo($config_id, array $upData)
    {
        Db::table('qj_config')->where(['id' => $config_id])->update($upData);
        $res['success'] = true;
        $res['desc'] = '修改成功';
        $res['errorcode'] = '';
        return $res;
    }

    public function delConfigInfo($config_id)
    {
        Db::table('qj_config')->where(['id' => $config_id])->delete();
        $res['success'] = true;
        $res['desc'] = '删除成功';
        $res['errorcode'] = '';
        return $res;
    }

    public function getConfigInfo()
    {
        $info = Db::table('qj_config')->where(['status' => 1])->order('id desc')->find();
        $res['success'] = true;
        $res['desc'] = '';
        $res['errorcode'] = '';
        $res['data'] = $info;
        return $res;
    }


}